function * fn () {
    yield 1;
    yield 2;
    return 'end';
}

var g = fn();

console.log(g.next());
console.log(g.next());
console.log(g.next());
console.log(g.next());

// { value: 1, done: false }
// { value: 2, done: false }
// { value: 'end', done: true }
// { value: undefined, done: true }